/**
 * Copyright 2007-2008. Chongqing First Information & Network Co., Ltd. All
 * rights reserved. <a>http://www.cqfirst.com.cn</a>
 */
package com.cqcis.uip.base.framework;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import org.apache.mina.common.ByteBuffer;

import com.cqcis.uip.base.framework.common.Task;
import com.cqcis.uip.base.framework.core.SocketClientTaskContextAfterProcessor;


/**
 * @author huangmy
 * @date   2007-12-21
 */
public class FrameworkConstants {
	/*------------任务处理错误描述--------------*/
	public final static String TASK_STATE_MSG_SERVICE_DEACTIVE = "目标端点对应服务不可用";
	public final static String TASK_STATE_MSG_DEALING = "正处理";
	public final static String TASK_STATE_MSG_PLATFORM_DEALING = "平台正处理";
	public final static String TASK_STATE_MSG_REMOTE_HOST_UNREACHED = "远程服务器无法连接";
	public final static String TASK_STATE_MSG_DISPATCH_ERROR = "任务分派异常";
	public final static String TASK_STATE_MSG_TASK_SCHEDULE_ERROR = "提交任务到服务失败";
	public final static String TASK_STATE_MSG_INTERFACE_PROCESS_ERROR = "服务程序处理异常";
	public final static String TASK_STATE_MSG_INTERFACE_TIMEOUT = "对端系统处理超时";
	public final static String TASK_STATE_MSG_REMOTE_FAILURE = "对端系统处理失败";
	public final static String TASK_STATE_MSG_REMOTE_SUCCESS = "对端系统处理成功";
	public final static String TASK_STATE_MSG_SERVICE_FORCE_CLOSED_SESSION = "链接被程序强制关闭";
	public final static String TASK_STATE_MSG_REMOTE_CLOSS_SESSION = "对端系统关闭链接";
	public final static String TASK_STATE_MSG_REMOTE_DATA_FORMAT_ERROR = "对端系统数据格式错误";
	public final static String TASK_STATE_MSG_REMOTE_DEALNG = "对端系统正处理";
	public final static String TASK_STATE_MSG_SUCESS = "处理成功";
	public final static String TASK_STATE_MSG_DONE = "处理完成";
	public final static String TASK_STATE_MSG_ERROR = "处理失败";
    		
	/* 写 socket 等待时间, 超时失败*/
	public final static long SOCKET_WRITE_TIMEOUT = 3 * 1000;
	private final static String CONSTANTS_NAME = FrameworkConstants.class.getName();
	
	/* session实例, 可能是socket链接, 也可以是自定义session */
	public final static String TASK_ATTRIBUTE_SESSION = CONSTANTS_NAME + "task_bind_session";
	
	/* 端点类型 */	
	public final static String ENDPOINT_ATTRIBUTE_ORDER_TYPE = CONSTANTS_NAME + "endpoint_attribute_order_type";
	
	/* 日志记录序列号 */	
	public final static String LOG_RECORDID = CONSTANTS_NAME + "task_atrribute_log_record_id";
	
	/* 日志对象名称 */
    public final static String INTERFACE_LOG = CONSTANTS_NAME + "interface_log";
    
    /* 字节流记录名称 */
    public final static String INTERFACE_STREAM_RECORD = CONSTANTS_NAME + "interface_stream_record";
    // 关闭字节流记录功能
    public final static String INTERFACE_STREAM_RECORD_CLOSED = CONSTANTS_NAME + "INTERFACE_STREAM_RECORD_CLOSED";
    
    /* 字节流日志路径分隔符 */
    public final static String STREAM_LOG_PATH_STOKEN = "stream";
    
    public final static Set<ByteBuffer> VIRTUAL_NO_DATA_BUFFERS = Collections.synchronizedSet(new HashSet<ByteBuffer>());
    
    public final static Set<ByteBuffer> VIRTUAL_TRY_TIMEOUT_BUFFERS = Collections.synchronizedSet(new HashSet<ByteBuffer>());
    
    /* 日志接收时间 */
    public final static String STREAM_LOG_RECVTIME = CONSTANTS_NAME + "stream_log_recvtime";
    
    /* 日志发送时间 */
    public final static String STREAM_LOG_SENDTIME = CONSTANTS_NAME + "stream_log_sendtime";
    
    /* 业务层线程名称前缀 */
    public final static String SERVICE_THREAD_NAME_PREFIX = "UIP-SERVICE";
    
    /* bundle属性配置 */
    public final static String BUNDLE_PROPERTIES_CONFIG = CONSTANTS_NAME + "bundle_properties_config";
    
    public static String RS_ATTR_STARTTIME = CONSTANTS_NAME + "rs_attr_starttime"; // 服务启动时间
    
    // stop等待时间
    public final static long RS_STOP_AWAIT_TIME = 5000; // 5000 毫秒
    
    // socket服务不写二进制数据
    public final static String STREAM_LOG_NOT_WRITED = CONSTANTS_NAME + "stream_log_not_writed";
    
    // 同步Task
    public final static String TASK_ATTR_SYNC = Task.class.getName() + "_task_attr_sync";
    
    // 放入超时等待池时间上限
    public final static long MAXTIME_FOR_PUTTIMEOUTPOOL = 180 * 1000;// 180s
    
    // result
    public final static String TASK_SYNCCTQ_FOR_RESULT = CONSTANTS_NAME + "TASK_SYNCCTQ_FOR_RESULT";
    public final static String TASK_SYNCCTQ_FOR_TASK = CONSTANTS_NAME + "TASK_SYNCCTQ_FOR_TASK";
    
    // 服务session id
    public final static String SESSION_ID_FOR_RS = CONSTANTS_NAME + "SESSION_ID_FOR_RS";
    
    public final static String TELNETFIRSTSEND_03 = "TELNETFIRSTSEND_03_" + CONSTANTS_NAME;
    
    // 接口操作日志
    public final static String RSOPERATOR_LOG = "RSOPERATOR_LOG_" + CONSTANTS_NAME;
    
    public final static String HAVA_SET_PENDRESULT = "HAVA_SET_PENDRESULT_" + CONSTANTS_NAME;
    
    public final static String TASK_IGNORE_AFTERPROCESSRESULT = "TASK_IGNORE_AFTERPROCESSRESULT_" + CONSTANTS_NAME;
    
    public final static String SOCKET_CLIENT_TASK_AFTERPROCESSOR = "SOCKET_CLIENT_TASK_AFTERPROCESSOR_" + SocketClientTaskContextAfterProcessor.class.getName();
    
    public final static String TASK_BLOCKINNG_PROCESS_SYNC = "TASK_BLOCKINNG_PROCESS_SYNC_" + FrameworkConstants.class.getName();
    
    // 分布式支持参数
    public final static String CLUSTER_SWITCH = "CLUSTER_SWITCH_" + CONSTANTS_NAME;
    public final static String CLUSTER_CT = "CT_CLUSTER_SWITCH_" + CONSTANTS_NAME;
    public final static String CLUSTER_CALLBAK = "CALLBAK_CLUSTER_SWITCH_" + CONSTANTS_NAME;
    
    public final static String WEBAPP_EXTRA_PATH = "../configuration/org.eclipse.osgi/webapps";
    public final static String ROLE_WEBAPP_CONFIG = "Role.WEBAPP";
        
    // 默认的属性配置
    public final static String[][] DEFAULT_FILE_PROPS_KEY_VALUE = new String[][] {
    	{"com.cqcis.uip.streamRecord", "true"},
    	{"com.cqcis.uip.timeout", "60000"},
    	{"com.cqcis.uip.keeplive", "false"}
    };
}
